using UnityEngine;
using System.Collections;

public class Save : MonoBehaviour {
	
	public static Save save;
	
	public string chapter;
	public string checkpointUid;
	public Trigger[] triggers;
	public Checkpoint[] checkpoints;
	public int seed = 0;
	
	public void saveGame() {
		string triggerData = "";
		string checkpointData = "";
		foreach (Trigger t in triggers) {
			triggerData += t.uid + ":";
			triggerData += (t.activated) ? "1" : "0";
			triggerData += "#";
		}
		
		foreach (Checkpoint c in checkpoints) {
			checkpointData += c.uid + "#";
		}
		/**
		 * File syntax:
		 * <Chapter>;<Current Checkpoint>;<trg0:act?(0/1)#trgN:act(0/1)>;<cp1#cpN>;<seed>
		 * <Chapter>: The name of the current chapter, ex: Chapter1TrainStation
		 * <Current Checkpoint>: The UID of the last checkpoint the player saved on.
			 * <trg0: The UID of the first trigger of that chapter, so the game knows if
			 * that trigger is triggered, before the save was loaded, or not.
			 * :act>: If that trigger has been activated/triggered. Represented by an int 
			 * value, 0 (false) or 1 (true).
			 * <trgN: The UID of one of the other triggers in the selected chapter.
			 * :act>: ^See above ":act>
		 	* <cp0*: The UID of the first checkpoint in the selected chapter.
		 	* <cpN: The UID of other triggers in the selected chapter.
		 * Chapter1TrainStation;cp01;trg01:0#trg02:0;cp01#cp02;0
		 **/
		System.IO.File.WriteAllText("./save.sav", 
			chapter + ";" + 
			checkpointUid + ";" + 
			triggerData + ";" + 
			checkpointData + ";" + 
			seed);
	}
}
